package com.dailyblue.java.spring.boot.security.controller;

import com.dailyblue.java.spring.boot.commons.util.JsonResult;
import com.dailyblue.java.spring.boot.commons.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/security")
@Slf4j
public class SecurityExampleController {
    @GetMapping("/a")
    @PreAuthorize("hasAuthority('/users/find')")
    public JsonResult a() {
        log.info("进入了SecurityExampleController的a方法中。");
        return ResultTool.success("This is SecurityExampleController`a method!");
    }
    @GetMapping("/b")
    @PreAuthorize("hasAuthority('/users/save')")
    public JsonResult b() {
        log.info("进入了SecurityExampleController的b方法中。");
        return ResultTool.success("This is SecurityExampleController`b method!");
    }
    @GetMapping("/c")
    @PreAuthorize("hasAnyAuthority('/users/find','/users/update')")
    public JsonResult c() {
        log.info("进入了SecurityExampleController的c方法中。");
        return ResultTool.success("This is SecurityExampleController`c method!");
    }
    @GetMapping("/d")
    @PreAuthorize("hasAuthority('/powers/find_power')")
    public JsonResult d() {
        log.info("进入了SecurityExampleController的d方法中。");
        return ResultTool.success("This is SecurityExampleController`d method!");
    }
}
